package 枚举与尺聚法;

public class Solution {
    public static void main(String[] args) {
        int[] arr = {-1, 0, 3, 5, 9, 12};
        long start1 = System.nanoTime();
        System.out.println(search(arr, 0, arr.length, 9));
        long end1 = System.nanoTime();
        System.out.println(end1 - start1);
    }

    static public int search(int[] nums, int left, int right, int target) {
        if (left > right) { //没有找到
            return -1;
        }
        int mid = (left + right) / 2;
        int midNum = nums[mid];
        if (target > midNum) { //向右递归
            return search(nums, mid + 1, right, target);
        } else if (target < midNum) {//向左递归
            return search(nums, left, mid - 1, target);
        } else {
            return mid;
        }
    }
}
